package com.pocketsweet.ui;

import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;

import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ContentView;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.pocketsweet.R;
import com.pocketsweet.chat.ui.activity.BaseActivity;
import com.pocketsweet.service.UserService;
import com.pocketsweet.ui.uilib.HeaderLayout;
import com.pocketsweet.ui.uilib.HeaderLayout.HeaderStyle;
import com.pocketsweet.ui.uilib.HeaderLayout.onLeftContainerListener;

@ContentView(R.layout.activity_about)
public class About extends BaseActivity {

	private HeaderLayout header;
	private PackageManager manager;
	private PackageInfo info = null;
	
	@ViewInject(R.id.tvProtocol)
	private TextView tvProtocol;

	@ViewInject(R.id.aboutIcon)
	private ImageView aboutIcon;
	
	@ViewInject(R.id.aboutApps)
	private TextView aboutApps;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		ViewUtils.inject(this);
		initView();
		setHeaderFunction();
	}

	private void initView() {
		manager = About.this.getPackageManager();
		try {
			info = manager.getPackageInfo(About.this.getPackageName(), 0);
			aboutApps.setText("口袋恋人" + info.versionName.toString());
		} catch (NameNotFoundException e) {

			// TODO Auto-generated catch block

			e.printStackTrace();
		}
		UserService.displayRoundDrawable(R.drawable.icon_about, aboutIcon);
		tvProtocol.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// 打开协议网址
				Intent intent = new Intent(About.this, WebViews.class);
				intent.putExtra("url", "http://www.pocketsweet.com/protocol");
				startActivity(intent);

			}
		});

	}

	public void setHeaderFunction() {
		header = (HeaderLayout) findViewById(R.id.mainHeader);
		header.init(HeaderStyle.IMG_TITLE_TEXT);
		header.setRightText("");
		header.setMiddleText("关于我们");
		header.setLeftContainerClickListener(new onLeftContainerListener() {

			@Override
			public void onClick() {
				About.this.finish();
			}
		});
	}

	@Override
	protected void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
	}

	@Override
	protected void onRestoreInstanceState(Bundle savedInstanceState) {
		super.onRestoreInstanceState(savedInstanceState);
	}
}
